# 单继承
# 父类

# 最简单的继承(没有构造函数继承)
class Father(object):
    def say(self):
        print("说话的方法")


# 子类  在子类中传入父类的名称,子类就继承了父类
class Son(Father):
    def eat(self):
        print("吃饭的方法")


father = Father()
son = Son()


# son.eat()
# son.say()

# 有构造函数的单继承
# 父类
class Animal(object):
    def __init__(self, name, sex):
        self.name = name
        self.sex = sex

    def eat(self):
        print("自然界的法则是:弱肉强食")


# 子类
class Dog(Animal):
    def __init__(self, name, sex, weight):  # 先继承父类的属性,再重构
        # 1.第一种经典的写法:
        '''
        Animal.__init__(self,name,sex)   # 继承父类的属性
        self.name = name
        self.sex = sex
        self.weight =weight
        '''

        # 2.第二种:隐式的继承父类的构造函数
        super(Dog, self).__init__(name, sex)
        self.weight = weight  # 定义子类自己的属性

    def run(self):
        print("狼行千里吃肉,狗走万里吃粑粑!")


dog = Dog("中华土狗", "公", 30)
print(dog.name)
print(dog.sex)
print(dog.weight)
dog.eat()
dog.run()
